<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>查找时间差</title>
</head>

<body>
  <script>
    const arr = ["23:59", "00:05", "00:00"];
    const array = (arr = []) => {
      const find = (str = '') => str.split(':').map(time => parseInt(time, 10))
      const mapped = arr.map((time) => {
        const [hour1, minute1] = find(time)
        return hour1 * 60 + minute1
      });
      const sorted = []
      let isrepeating = false
      mapped.forEach((time) => {
        if (sorted[time] !== undefined || sorted[time + 24 * 60] !== undefined) {
          isrepeating = true
        }
        sorted[time] = time
        sorted[time + 24 * 60] = time + 24 * 60
      })
      if (isrepeating) {
        return 0
      }
      let min = Infinity
      let prev = null
      for (let i = 0; i < sorted.length; i++) {
        if (sorted[i] !== undefined) {
          if (prev) {
            min = Math.min(min, sorted[i] - prev)
          }
          prev = sorted[i]
        }
      }
      return min
    };
    console.log(array(arr));

  </script>
</body>

</html>